package com.sanji.sjmallmodule.login;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sanji.sjmallapp.BaseActivity;
import com.sanji.sjmallapp.R;
import com.sanji.sjmallconfig.ConfigAPI;
import com.sanji.sjmallconfig.ConfigConts;
import com.sanji.sjmallmanager.http.NoHttpCallBack;
import com.sanji.sjmallmanager.http.NoHttpListener;
import com.sanji.sjmallutils.Tools;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RegisterActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener, NoHttpListener {
    ListView proviceListview;
    ListView cityListview;
    ListView townListview;
    ListView streetListview;
    @BindView(R.id.register_user_region_tv)
    TextView regionZoneTv;
    @BindView(R.id.register_user_reion_relative)
    RelativeLayout registerUserReionRelative;
    ImageView closePop;
    TextView popRegionProviceTv;
    View popRegionProviceView;
    TextView popRegionCityTv;
    View popRegionCityView;
    TextView popRegionTownsTv;
    View popRegionTownView;
    TextView popRegionStreetTv;
    View popRegionStreetView;
    @BindView(R.id.register_btn)
    Button registerBtn;
    @BindView(R.id.register_shop_name_edit)
    EditText registerShopNameEdit;
    @BindView(R.id.register_user_name_edit)
    EditText registerUserNameEdit;
    @BindView(R.id.register_user_phone_edit)
    EditText registerUserPhoneEdit;
    @BindView(R.id.register_user_location_edit)
    EditText registerUserLocationEdit;


    private PopupWindow pw;
    private List<RegisterRegionBean> proviceData;
    private List<RegisterRegionBean> cityData;
    private List<RegisterRegionBean> townData;
    private List<RegisterRegionBean> streetData;
    private RegisterRegionAdpter proviceAdapter;
    private RegisterRegionAdpter cityAdapter;
    private RegisterRegionAdpter townAdapter;
    private RegisterRegionAdpter streetAdapter;

    private HashMap<Integer, String> regionZoneMap = new HashMap<>();

    private WindowManager.LayoutParams windowLp;
    private Request<JSONObject> request;
    private List<RegisterRegionBean> regionData;
    private int regionAType;//区域属性,0县区,1乡镇;仅限镇级单位,其他级别为空
    private String provinceStr;//省区
    private String cityStr;//市区
    private String districtStr;//县区
    private String townStr;//乡镇

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        registerUserReionRelative.setOnClickListener(this);
        proviceData = new ArrayList<RegisterRegionBean>();
        cityData = new ArrayList<RegisterRegionBean>();
        townData = new ArrayList<RegisterRegionBean>();
        streetData = new ArrayList<RegisterRegionBean>();
        regionData = new ArrayList<RegisterRegionBean>();
        registerBtn.setOnClickListener(this);


        windowLp = this.getWindow().getAttributes();
    }

    /**
     * popWindow中view
     */
    public void initPopView() {
        View view = LayoutInflater.from(mCtx).inflate(R.layout.activity_popwindow_register_region, null);
        //选中的tv
        popRegionProviceTv = (TextView) view.findViewById(R.id.register_pop_region_provice_tv);
        popRegionProviceTv.setOnClickListener(this);
        popRegionProviceView = view.findViewById(R.id.register_pop_region_provice_view);
        popRegionCityTv = (TextView) view.findViewById(R.id.register_pop_region_city_tv);
        popRegionCityTv.setOnClickListener(this);
        popRegionCityView = view.findViewById(R.id.register_pop_region_city_view);
        popRegionTownsTv = (TextView) view.findViewById(R.id.register_pop_region_towns_tv);
        popRegionTownsTv.setOnClickListener(this);
        popRegionTownView = view.findViewById(R.id.register_pop_region_town_view);
        popRegionStreetTv = (TextView) view.findViewById(R.id.register_pop_region_street_tv);
        popRegionStreetTv.setOnClickListener(this);
        popRegionStreetView = view.findViewById(R.id.register_pop_region_street_tv);
        //listview
        proviceListview = (ListView) view.findViewById(R.id.register_pop_provice_listview);
        proviceListview.setOnItemClickListener(this);
        cityListview = (ListView) view.findViewById(R.id.register_pop_city_listview);
        cityListview.setOnItemClickListener(this);
        townListview = (ListView) view.findViewById(R.id.register_pop_town_listview);
        townListview.setOnItemClickListener(this);
        streetListview = (ListView) view.findViewById(R.id.register_pop_street_listview);
        streetListview.setOnItemClickListener(this);
        closePop = (ImageView) view.findViewById(R.id.register_close_pop);

        proviceAdapter = new RegisterRegionAdpter(proviceData, this);
        cityAdapter = new RegisterRegionAdpter(cityData, this);
        streetAdapter = new RegisterRegionAdpter(streetData, this);
        townAdapter = new RegisterRegionAdpter(townData, this);
        proviceListview.setAdapter(proviceAdapter);
        cityListview.setAdapter(cityAdapter);
        townListview.setAdapter(townAdapter);
        streetListview.setAdapter(streetAdapter);
        if (null == pw) {
            //popupwindow
            pw = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            pw.setFocusable(true);
            pw.setOutsideTouchable(true);
            pw.setBackgroundDrawable(this.getResources().getDrawable(R.color.colorLightGrey));
            pw.setAnimationStyle(R.style.my_popwindow);
            /**
             * 点击消失按钮
             */
            closePop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pw.dismiss();
                }
            });
            /**
             * pw消失后，背景颜色改变
             */
            pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    windowLp.alpha = 1.0f;
                    RegisterActivity.this.getWindow().setAttributes(windowLp);
                }
            });
        }
        pw.showAsDropDown(registerUserReionRelative);
        //默认请求县级数据
        String proviceUrl = ConfigAPI.REGION_URL + "id=";
        getProviceData(proviceUrl);
        if (proviceData == null) {
            proviceData.addAll(regionData);
        }
        proviceAdapter.notifyAdapter(proviceData);
    }

    /**
     * 网络请求省份的数据
     */
    public void getProviceData(String url) {
        request = NoHttp.createJsonObjectRequest(url, RequestMethod.GET);
        request.setCancelSign(0);
        NoHttpCallBack.getInstance().add(mCtx, 0, request, this, true, true);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.register_user_reion_relative:
                windowLp.alpha = 0.6f;
                this.getWindow().setAttributes(windowLp);
                initPopView();
                break;
            case R.id.register_pop_region_provice_tv:
                setShowView(0);
                break;
            case R.id.register_pop_region_city_tv:
                setShowView(1);
                break;
            case R.id.register_pop_region_towns_tv:
                setShowView(2);
                break;
            case R.id.register_pop_region_street_tv:
                setShowView(3);
                break;
            case R.id.register_btn:
                //申请注册
                requestRegister();
                break;
        }
    }

    private void setShowView(int index) {
        switch (index) {
            case 0:
                //listview显隐
                proviceListview.setVisibility(View.VISIBLE);
                cityListview.setVisibility(View.GONE);
                townListview.setVisibility(View.GONE);
                streetListview.setVisibility(View.GONE);
                //设置title样式
                setZoneTitleStyle(0);
                break;
            case 1:
                proviceListview.setVisibility(View.GONE);
                cityListview.setVisibility(View.VISIBLE);
                townListview.setVisibility(View.GONE);
                streetListview.setVisibility(View.GONE);
                setZoneTitleStyle(1);
                break;
            case 2:
                proviceListview.setVisibility(View.GONE);
                cityListview.setVisibility(View.GONE);
                townListview.setVisibility(View.VISIBLE);
                streetListview.setVisibility(View.GONE);
                setZoneTitleStyle(2);
                break;
            case 3:
                proviceListview.setVisibility(View.GONE);
                cityListview.setVisibility(View.GONE);
                townListview.setVisibility(View.GONE);
                streetListview.setVisibility(View.VISIBLE);
                setZoneTitleStyle(3);
                break;
        }
    }


    /**
     * 点击title设置样式
     *
     * @param index
     */
    private void setZoneTitleStyle(int index) {
        switch (index) {
            case 0:
                popRegionProviceView.setVisibility(View.VISIBLE);
                popRegionProviceTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                popRegionCityView.setVisibility(View.GONE);
                popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionTownView.setVisibility(View.GONE);
                popRegionTownsTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionStreetView.setVisibility(View.GONE);
                popRegionStreetTv.setTextColor(getResources().getColor(R.color.color_848484));
                break;
            case 1:
                popRegionProviceView.setVisibility(View.GONE);
                popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionCityView.setVisibility(View.VISIBLE);
                popRegionCityTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                popRegionTownView.setVisibility(View.GONE);
                popRegionTownsTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionStreetView.setVisibility(View.GONE);
                popRegionStreetTv.setTextColor(getResources().getColor(R.color.color_848484));
                break;
            case 2:
                popRegionProviceView.setVisibility(View.GONE);
                popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionCityView.setVisibility(View.GONE);
                popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionTownView.setVisibility(View.VISIBLE);
                popRegionTownsTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                popRegionStreetView.setVisibility(View.GONE);
                popRegionStreetTv.setTextColor(getResources().getColor(R.color.color_848484));
                break;
            case 3:
                popRegionProviceView.setVisibility(View.GONE);
                popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionCityView.setVisibility(View.GONE);
                popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionTownView.setVisibility(View.GONE);
                popRegionTownsTv.setTextColor(getResources().getColor(R.color.color_848484));
                popRegionStreetView.setVisibility(View.VISIBLE);
                popRegionStreetTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                break;
        }
    }

    /**
     * item点击
     *
     * @param title
     */
    private void setZoneTitleStyle(String title, int index) {
        if (!regionZoneMap.containsKey(index)) {
            regionZoneMap.put(index, title);
            switch (index) {
                case 0:
                    popRegionProviceView.setVisibility(View.GONE);
                    popRegionProviceTv.setVisibility(View.VISIBLE);
                    popRegionProviceTv.setText(regionZoneMap.get(0));
                    popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionCityView.setVisibility(View.VISIBLE);
                    popRegionCityTv.setVisibility(View.VISIBLE);
                    popRegionCityTv.setText(getString(R.string.choose_please));
                    popRegionCityTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                    popRegionTownView.setVisibility(View.GONE);
                    popRegionTownsTv.setVisibility(View.GONE);
                    popRegionStreetView.setVisibility(View.GONE);
                    popRegionStreetTv.setVisibility(View.GONE);
                    break;
                case 1:
                    popRegionProviceView.setVisibility(View.GONE);
                    popRegionProviceTv.setVisibility(View.VISIBLE);
                    popRegionProviceTv.setText(regionZoneMap.get(0));
                    popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionCityView.setVisibility(View.GONE);
                    popRegionCityTv.setVisibility(View.VISIBLE);
                    popRegionCityTv.setText(regionZoneMap.get(1));
                    popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionTownView.setVisibility(View.VISIBLE);
                    popRegionTownsTv.setVisibility(View.VISIBLE);
                    popRegionTownsTv.setText(getString(R.string.choose_please));
                    popRegionTownsTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                    popRegionStreetView.setVisibility(View.GONE);
                    popRegionStreetTv.setVisibility(View.GONE);
                    break;
                case 2:
                    popRegionProviceView.setVisibility(View.GONE);
                    popRegionProviceTv.setVisibility(View.VISIBLE);
                    popRegionProviceTv.setText(regionZoneMap.get(0));
                    popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionCityView.setVisibility(View.GONE);
                    popRegionCityTv.setVisibility(View.VISIBLE);
                    popRegionCityTv.setText(regionZoneMap.get(1));
                    popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionTownView.setVisibility(View.GONE);
                    popRegionTownsTv.setVisibility(View.VISIBLE);
                    popRegionTownsTv.setText(regionZoneMap.get(2));
                    popRegionTownsTv.setTextColor(getResources().getColor(R.color.color_848484));
                    popRegionStreetView.setVisibility(View.VISIBLE);
                    popRegionStreetTv.setVisibility(View.VISIBLE);
                    popRegionStreetTv.setText(getString(R.string.choose_please));
                    popRegionStreetTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                    break;
            }

        } else {
            String value = regionZoneMap.get(index);
            if (!title.equals(value)) {
                switch (index) {
                    case 0:
                        popRegionProviceView.setVisibility(View.GONE);
                        popRegionProviceTv.setVisibility(View.VISIBLE);
                        popRegionProviceTv.setText(title);
                        popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionCityView.setVisibility(View.VISIBLE);
                        popRegionCityTv.setVisibility(View.VISIBLE);
                        popRegionCityTv.setText(getString(R.string.choose_please));
                        popRegionCityTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                        popRegionTownView.setVisibility(View.GONE);
                        popRegionTownsTv.setVisibility(View.GONE);
                        popRegionStreetView.setVisibility(View.GONE);
                        popRegionStreetTv.setVisibility(View.GONE);
                        break;
                    case 1:
                        popRegionProviceView.setVisibility(View.GONE);
                        popRegionProviceTv.setVisibility(View.VISIBLE);
                        popRegionProviceTv.setText(regionZoneMap.get(0));
                        popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionCityView.setVisibility(View.GONE);
                        popRegionCityTv.setVisibility(View.VISIBLE);
                        popRegionCityTv.setText(title);
                        popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionTownView.setVisibility(View.VISIBLE);
                        popRegionTownsTv.setVisibility(View.VISIBLE);
                        popRegionTownsTv.setText(getString(R.string.choose_please));
                        popRegionTownsTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                        popRegionStreetView.setVisibility(View.GONE);
                        popRegionStreetTv.setVisibility(View.GONE);
                        break;
                    case 2:
                        popRegionProviceView.setVisibility(View.GONE);
                        popRegionProviceTv.setVisibility(View.VISIBLE);
                        popRegionProviceTv.setText(regionZoneMap.get(0));
                        popRegionProviceTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionCityView.setVisibility(View.GONE);
                        popRegionCityTv.setVisibility(View.VISIBLE);
                        popRegionCityTv.setText(regionZoneMap.get(1));
                        popRegionCityTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionTownView.setVisibility(View.GONE);
                        popRegionTownsTv.setVisibility(View.VISIBLE);
                        popRegionTownsTv.setText(title);
                        popRegionTownsTv.setTextColor(getResources().getColor(R.color.color_848484));
                        popRegionStreetView.setVisibility(View.VISIBLE);
                        popRegionStreetTv.setVisibility(View.VISIBLE);
                        popRegionStreetTv.setText(getString(R.string.choose_please));
                        popRegionStreetTv.setTextColor(getResources().getColor(R.color.colorLightRed));
                        break;
                }
                //重置
                int size = regionZoneMap.size();
                if (size > index) {
                    for (int j = index; j < size; j++) {
                        regionZoneMap.remove(j);
                    }
                }
                regionZoneMap.put(index, title);
            }
        }


    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (proviceListview.isShown()) {
            RegisterRegionBean proviceBean = (RegisterRegionBean) proviceAdapter.getItem(i);
            popRegionProviceTv.setText(proviceBean.getRegionName());
            popRegionProviceView.setVisibility(View.GONE);
            popRegionCityTv.setVisibility(View.VISIBLE);
            popRegionCityView.setVisibility(View.VISIBLE);
            proviceListview.setVisibility(View.GONE);
            cityListview.setVisibility(View.VISIBLE);
            //网络请求市级数据
            String cityUrl = ConfigAPI.REGION_URL + "id=" + proviceBean.getRegionId();
            getProviceData(cityUrl);

            cityData.clear();
            cityData.addAll(regionData);
            cityAdapter.notifyAdapter(cityData);
            setZoneTitleStyle(proviceBean.getRegionName(), 0);
            provinceStr = proviceBean.getRegionName();

        } else if (cityListview.isShown()) {
            RegisterRegionBean cityBean = (RegisterRegionBean) cityAdapter.getItem(i);
            popRegionCityTv.setText(cityBean.getRegionName());
            popRegionCityView.setVisibility(View.GONE);
            popRegionProviceView.setVisibility(View.GONE);
            popRegionTownsTv.setVisibility(View.VISIBLE);
            popRegionTownView.setVisibility(View.VISIBLE);
            popRegionStreetTv.setVisibility(View.INVISIBLE);
            popRegionStreetView.setVisibility(View.INVISIBLE);

            cityListview.setVisibility(View.GONE);
            townListview.setVisibility(View.VISIBLE);

            //网络请求区数据
            String townUrl = ConfigAPI.REGION_URL + "id=" + cityBean.getRegionId();
            getProviceData(townUrl);
            townData.clear();
            townData.addAll(regionData);

            townAdapter.notifyAdapter(townData);

            setZoneTitleStyle(cityBean.getRegionName(), 1);
            cityStr = cityBean.getRegionName();
        } else if (townListview.isShown()) {
            RegisterRegionBean townBean = (RegisterRegionBean) townAdapter.getItem(i);
            popRegionTownsTv.setText(townBean.getRegionName());
            popRegionTownView.setVisibility(View.GONE);
            townListview.setVisibility(View.GONE);
            streetListview.setVisibility(View.VISIBLE);


            //网络请求区数据
            String streetUrl = ConfigAPI.REGION_URL + "id=" + townBean.getRegionId();
            getProviceData(streetUrl);
            streetData.clear();
            streetData.addAll(regionData);

            streetAdapter.notifyAdapter(streetData);
            setZoneTitleStyle(townBean.getRegionName(), 2);
            districtStr = townBean.getRegionName();
        } else {
            RegisterRegionBean streetBean = (RegisterRegionBean) streetAdapter.getItem(i);
            popRegionStreetView.setVisibility(View.VISIBLE);
            popRegionStreetTv.setVisibility(View.VISIBLE);
            popRegionStreetTv.setText(streetBean.getRegionName());
            regionZoneMap.put(3, streetBean.getRegionName());
            //获得区域类型，0县区,1乡镇;仅限镇级单位,其他级别为空
            regionAType = streetBean.getRegionAtype();
            townStr = streetBean.getRegionName();
            setRegionZoneDate();

            if (pw != null && pw.isShowing()) {
                pw.dismiss();
            }
        }
    }

    /**
     * 为地区赋值
     */
    private void setRegionZoneDate() {
        if (regionZoneMap != null) {
            int size = regionZoneMap.size();
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < size; i++) {
                buffer.append(regionZoneMap.get(i)).append("-");

            }
            String address = buffer.substring(0, buffer.length() - 1).toString();
            regionZoneTv.setText(address);
        }
    }

    @Override
    public void onSuccessed(int what, Response response) {
        switch (what) {
            case 0:
                int requestCode = response.getHeaders().getResponseCode();
                JSONObject object = new JSONObject();
                JSONArray array = new JSONArray();
                if (requestCode == 200) {
                    object = (JSONObject) response.get();
                    String status = object.optString(ConfigConts.STATUS_STRING);
                    if (status.equals(ConfigConts.STATUS_SUCCESS)) {
                        array = object.optJSONArray("result");
                        regionData.clear();
                        if (array.length() > 0) {
                            for (int i = 0; i < array.length(); i++) {
                                int regionId = object.optInt("id");
                                String regionName = object.optString("name");
                                String regionPath = object.optString("path");
                                int regionAtype = object.optInt("atype");
                                String regionNamepath = object.optString("namepath");
                                String regionGrade = object.optString("grade");
                                RegisterRegionBean regionBean = new RegisterRegionBean(regionId, regionName, regionAtype, regionPath, regionNamepath, regionGrade);
                                regionData.add(regionBean);
                            }
                        } else {
                            Tools.toastTools(mCtx, "暂时没有获取到数据，请重试");
                        }
                    } else if (status.equals(ConfigConts.STATUS_ERROR)) {
                        String errorMsg = object.optString(ConfigConts.ERRORMSG);
                        Tools.toastTools(mCtx, errorMsg);
                    }
                }
                break;
            case 1:
                int code = response.getHeaders().getResponseCode();
                JSONObject json = new JSONObject();
                if (code == 200) {
                    json = (JSONObject) response.get();
                    String status = json.optString(ConfigConts.STATUS_STRING);
                    if (status.equals(ConfigConts.STATUS_SUCCESS)) {
                        String successMsg = json.optString(ConfigConts.SUCCESSMSG);
                        Tools.toastTools(mCtx, successMsg);
                        finish();
                    } else if (status.equals(ConfigConts.STATUS_ERROR)) {
                        String errorMsg = json.optString(ConfigConts.ERRORMSG);
                        Tools.toastTools(mCtx, errorMsg);
                    }
                } else {
                    Tools.toastTools(mCtx, getString(R.string.register_false));
                }
                break;
        }

    }

    @Override
    public void onFailed(int what, Response response) {
        switch (what) {
            case 0:
                Tools.toastTools(mCtx, getString(R.string.request_false));
                break;
            case 1:
                Tools.toastTools(mCtx, getString(R.string.request_false));
                break;
        }
    }

    /***
     * 申请注册
     **/
    public void requestRegister() {
        request = NoHttp.createJsonObjectRequest(ConfigAPI.REGISTER_URL, RequestMethod.POST);
        String shopName = registerShopNameEdit.getText().toString().trim();
        String cityLocation = regionZoneTv.getText().toString().trim();
        String userName = registerUserNameEdit.getText().toString().trim();
        String phoneSting = registerUserPhoneEdit.getText().toString().trim();
        String userLocation = registerUserLocationEdit.getText().toString().trim();
        if (TextUtils.isEmpty(shopName)) {
            Tools.toastTools(mCtx, getString(R.string.register_input_shop_name));
            return;
        }
        if (TextUtils.isEmpty(cityLocation)) {
            Tools.toastTools(mCtx, getString(R.string.register_set_city));
            return;
        }
        if (TextUtils.isEmpty(userName)) {
            Tools.toastTools(mCtx, getString(R.string.register_input_username));
            return;
        }
        if (TextUtils.isEmpty(phoneSting)) {
            Tools.toastTools(mCtx, getString(R.string.register_input_phone));
            return;
        }
        if (TextUtils.isEmpty(userLocation)) {
            Tools.toastTools(mCtx, getString(R.string.register_input_address));
            return;
        }
        JSONObject object = new JSONObject();
        try {
            object.put("account", shopName);
            object.put("trueName", userName);
            object.put("province", provinceStr);
            object.put("city", cityStr);
            object.put("district", districtStr);
            object.put("town", townStr);
            object.put("address", userLocation);
            object.put("mobile", phoneSting);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        request.setDefineRequestBodyForJson(object);
        request.setCancelSign(1);
        NoHttpCallBack.getInstance().add(mCtx, 1, request, this, true, true);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        request.cancel();
    }
}
